package com.company.cloud.platform.modules.mgr.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.company.cloud.common.asserts.ValidatorUtils;
import com.company.cloud.common.auth.annotation.Authc;
import com.company.cloud.common.auth.annotation.StaffLogc;
import com.company.cloud.common.bean.BaseClientResult;
import com.company.cloud.common.bean.BaseResult;
import com.company.cloud.common.bean.LoginSimpleUserInfo;
import com.company.cloud.common.constant.BaseReturnEnum;
import com.company.cloud.common.exception.BusinessException;
import com.company.cloud.common.utils.AuthContextUtils;
import com.company.cloud.common.utils.CheckUtils;
import com.company.cloud.company.modules.api.request.*;
import com.company.cloud.company.modules.api.response.CompanyFull;
import com.company.cloud.page.modules.api.models.PageComponentModel;
import com.company.cloud.page.modules.api.request.*;
import com.company.cloud.page.modules.api.response.PageComponentPageResponse;
import com.company.cloud.page.modules.api.response.PageComponentResponse;
import com.company.cloud.page.modules.api.service.PageComponentClientService;
import com.company.cloud.platform.modules.mgr.controller.req.CompanyQuery4PageParam;
import com.company.cloud.platform.modules.mgr.controller.req.CompanyUpdateStateParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Authc
@RestController
@RequestMapping("/admin/mgr/pageComponent")
@Api(tags="Admin_MGR_页面组件管理")
public class PageComponentMgrController {
    @Autowired
    private PageComponentClientService pageComponentClientService;


    @PostMapping("/query")
    @ApiOperation(value="查询", response= PageComponentModel.class)
    public BaseResult query(@RequestBody PageComponentQueryParam params) {
        BaseClientResult<PageComponentPageResponse> response= pageComponentClientService.query(params);
        PageComponentPageResponse data=BaseClientResult.getResultData2Error(response);
        return BaseResult.ok(data);
    }

    @PostMapping("/add")
    @ApiOperation(value="新增", response=BaseResult.class)
    @StaffLogc(title = "新增页面组件", action = "新增页面组件", actionAdo = "页面组件")
    public BaseResult add(@RequestBody PageComponentSave2UpdateRequest params) {
        ValidatorUtils.validate(params);
        LoginSimpleUserInfo userInfo= AuthContextUtils.getUser();
        params.setClientUserId(userInfo.getId());
        params.setClientUserIp(userInfo.getIp());
        BaseClientResult<String> response = pageComponentClientService.save(params);
        CheckUtils.checkClientResult(response);
        return BaseResult.ok();
    }


    @PostMapping("/edit")
    @ApiOperation(value="修改", response=BaseResult.class)
    @StaffLogc(title = "修改页面组件", action = "修改页面组件", actionAdo = "页面组件")
    public BaseResult edit(@RequestBody PageComponentSave2UpdateRequest params) {
        LoginSimpleUserInfo userInfo= AuthContextUtils.getUser();
        params.setClientUserId(userInfo.getId());
        params.setClientUserIp(userInfo.getIp());
        BaseClientResult<String> response= pageComponentClientService.update(params);
        CheckUtils.checkClientResult(response);
        return BaseResult.ok();
    }

    @GetMapping("/get")
    @ApiOperation(value="获取", response= PageComponentModel.class)
    public BaseResult get(@RequestParam("code")String  code) {
        BaseClientResult<PageComponentModel> response=pageComponentClientService.getById(code);
        PageComponentModel data=BaseClientResult.getResultData2Error(response);
        return BaseResult.ok(response.getData());
    }


    @GetMapping("/del")
    @ApiOperation(value="删除", response=BaseResult.class)
    @StaffLogc(title = "删除页面组件", action = "删除页面组件", actionAdo = "页面组件")
    public BaseResult del(@RequestParam("code")String code) {
        LoginSimpleUserInfo userInfo= AuthContextUtils.getUser();
        PageComponentDeleteRequest request=new PageComponentDeleteRequest();
        request.setClientUserId(userInfo.getId());
        request.setClientUserIp(userInfo.getIp());
        request.setCode(code);
        BaseClientResult<String> response= pageComponentClientService.delete(request);
        CheckUtils.checkClientResult(response);
        return BaseResult.ok();
    }







//
//    @PostMapping("/frozen")
//    @ApiOperation(value="冻结", response=BaseResult.class)
//    public BaseResult frozen(@RequestBody CompanyUpdateStateParam params) {
//        LoginSimpleUserInfo userInfo= AuthContextUtils.getUser();
//        CompanyFrozenRequest request=new CompanyFrozenRequest();
//        request.setCompanyNo(params.getCompanyNo());
//        request.setOpIp(userInfo.getIp());
//        request.setOpUserId(userInfo.getId());
//        companyRemoteService.frozenCompany(request);
//        return BaseResult.ok();
//    }
//
//
//    @PostMapping("/unfreeze")
//    @ApiOperation(value="解冻", response=BaseResult.class)
//    public BaseResult unfreeze(@RequestBody CompanyUpdateStateParam params) {
//        LoginSimpleUserInfo userInfo= AuthContextUtils.getUser();
//        CompanyUnFreezeRequest request=new CompanyUnFreezeRequest();
//        request.setCompanyNo(params.getCompanyNo());
//        request.setOpIp(userInfo.getIp());
//        request.setOpUserId(userInfo.getId());
//        companyRemoteService.unfreezeCompany(request);
//        return BaseResult.ok();
//    }
//

//

}
